package com.chukun.netty.codec.customize;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

/**
 * @author chukun
 * long 类型处理
 */
public class NettyCustomizeByteToLongDecoder extends ByteToMessageDecoder {

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        System.out.println("NettyCustomizeByteToLongDecoder invoke");
        System.out.println("可读字节长度为: "+in.readableBytes());
        //long类型8个字节
        if(in.readableBytes()>=8){
            out.add(in.readLong());
        }
    }
}
